package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.statisVO;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisVOService;
import cn.wolfcode.luowowo.cache.util.RedisKeys;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * spring定时器，将redis数据持久化到mysql中
 */
//@Component
public class RedisDataPersistenceJob {

    @Reference
    private IStrategyStatisVOService strategyStatisVOService;
    @Reference
    private IStrategyDetailService strategyDetailService;

    @Scheduled(cron = "0/10 * * * * ?")
    public void doWork(){
        System.out.println("-------vo的持久化 开始-------");
        List<StrategyStatisVO> vos = strategyStatisVOService.listVo(RedisKeys.STRATEGY_STATIS_VO.join("*"));

        //update到数据库中
        for (StrategyStatisVO vo : vos) {
            statisVO statisVO = new statisVO();
            BeanUtils.copyProperties(vo, statisVO);
            strategyDetailService.updateStatisVo(statisVO);
        }
        System.out.println("-------vo的持久化 结束-------");
    }
}
